﻿
    //全局变量
    page = new Paging();
    param = {
        "TableName": "DMP_Bolg_Shuoshuo",
        "DataTime": null,
        "IndexDelIds": [],
        "DateType": 0,
        "IsRTData": true,
        "sortName": "PointNumber",
        "sortType": "desc",
        "Filter": {},
        "pagingCount": 10,
        "pagingNumber": 1
    }

    //分页对象
    function Paging() {
        this.config =
           {
               DivId: "dataTable_paginate",
               DivStyle: "",
               MaxNumber: 10
           }

        this.property = {
            indexNumber: 1,
            startNumber: 1,
            endNumber: 10,
        }

        paging_event(this);
        //动作
        if (typeof (Paging.initailed) == "undefined") {
            Paging.prototype.reDraw = function () {
                var htm = '<span  class="BackPage"> <a href="#" style="">&lt;上一页</a></span>\
                <span class="PageNumber"><a class="on " href="#">1</a>\
                <a class="" href="#">10</a></span>\
                <span class="NextPage"><a href="#" >下一页&gt;</a></span>';
                //分页对象
                var pagingObj = $("#" + this.config.DivId)
                //初步绘制出
                pagingObj.html("").html(htm);
                //上一页  页码  下一页 obj
                var pagingBackPage = pagingObj.find(".BackPage");
                var pagingNextPaga = pagingObj.find(".NextPage");
                var pagingNumber = pagingObj.find(".PageNumber");
                //对上一页下一页的绘制
                if (this.config.MaxNumber == this.property.indexNumber) {
                    pagingNextPaga.hide();
                }
                if (this.property.indexNumber == 1) {
                    pagingBackPage.hide();
                }
                //对数码的绘制
                pagingNumber.html("");
                for (var i = this.property.startNumber; i <= this.property.endNumber; i++) {
                    if (i > this.config.MaxNumber) {
                        continue;
                    }
                    var htm_code = '<a class="" href="#">' + i + '</a>';
                    if (i == this.property.indexNumber) {
                        htm_code = '<a class="on" href="#">' + i + '</a>';
                    }
                    pagingNumber.append(htm_code);
                }
            }

        }
        Paging.initailed = true;
    }

    //分页点击事件
    function paging_event(page) {
        $("#" + page.config.DivId).click(function (e) {
            var e = e || window.event,
                target = e.target || e.srcElement;
            //输出点击div的id   
            var indexObj = $(target); //当前点击对象
            //过滤
            if (indexObj[0].tagName != "A")
            { return false; }
            if (parseInt(indexObj.html()) == page.property.indexNumber) { return false; }
            var indexOn = $(this).find(".on");
            if (indexObj.html() == "&lt;上一页") {
                page.property.indexNumber--;
            }

            else if (indexObj.html() == "下一页&gt;") {
                page.property.indexNumber++;
            }
            else {
                page.property.indexNumber = parseInt(indexObj.html());
            }

            var NumberCount = (page.property.endNumber + 1 - page.property.startNumber);
            var Numberdown = page.property.startNumber + 3;
            var NumberUp = page.property.endNumber - 3;


            if (Numberdown > page.property.indexNumber) {
                page.property.startNumber = page.property.startNumber - (Numberdown - page.property.indexNumber);
                page.property.endNumber = page.property.endNumber - (Numberdown - page.property.indexNumber);
                if (page.property.startNumber < 1) {
                    page.property.startNumber = 1;
                    page.property.endNumber = NumberCount;
                }
            }
            if (page.property.indexNumber > NumberUp) {
                page.property.startNumber = page.property.startNumber + (page.property.indexNumber - NumberUp);
                page.property.endNumber = page.property.endNumber + (page.property.indexNumber - NumberUp);
                if (page.property.endNumber > page.config.MaxNumber) {
                    page.property.startNumber = page.config.MaxNumber - NumberCount + 1;
                    page.property.endNumber = page.config.MaxNumber;
                }
            }
            PagingClickAfter();
            page.reDraw();
        })
    }

    //数据初始化绘制
    function Initailing() {
        //s全局数据初始化
        param.DataTime = new Date(new Date().getTime()+8*60*60*1000);
        param.IndexDelIds = [];

        //加载后台数据并初始化数据列表和分页
      debugger
        $.post("/JsonDate/getmyTableByTableInfo", { "Tinfo_json": JSON.stringify(param) }, function (mytable, status) {
            if (status == "success") {
                var ssList = mytable.TableResult_DbList;
                var maxPage = Math.ceil(mytable.TableResult_Count / 10);
                //全局数据初始化
                param.IndexDelIds = mytable.TableInfo.IndexDelIds;
                //加载数据绘制
                var obj = $("tbody");
                dataDraw(ssList, obj);
                //加载页面绘制
                page.config =
            {
                DivId: "dataTable_paginate",
                DivStyle: "",
                MaxNumber: maxPage
            }
                page.property = {
                    indexNumber: 1,
                    startNumber: 1,
                    endNumber: 10 < maxPage ? 10 : maxPage,
                }
                page.reDraw();
            }
        });


    }


    //点击后 数据加载前事件
    function PagingClickAfter() {
        param.pagingNumber = page.property.indexNumber;
        
        $.post("/JsonDate/getmyTableByTableInfo", { "Tinfo_json": JSON.stringify(param) }, function (mytable, status) {
            if (status == "success") {
                var ssList = mytable.TableResult_DbList;
                //加载数据绘制
                var obj = $("tbody");
                dataDraw(ssList, obj)
            }
        });
    }

    function dataDraw(ssList, obj) {
        obj.html("");
        for (var i in ssList) {
            var item = ssList[i];
            var indexMach = parseInt(i) + 1;
            var cls = Math.ceil(indexMach / 2) == indexMach / 2 ? "odd" : "even";

            var ssContent = '<tr role="row" class="' + cls + '">\
        <td hidden>' + item.id + '</td>\
         <td class="sorting_1">' + (indexMach + (page.property.indexNumber-1)*(page.property.endNumber-page.property.startNumber+1)) + '</td>\
         <td>'+ item.MessageType + '</td>\
       <td>'+ item.Name + '</td>\
       <td><a href="' + item.MessagesAddress + '">' + item.MessagesAddress + '<a></td>\
       <td>'+ item.PageViewNumber + '</td>\
       <td>'+ item.CommentNumber + '</td>\
       <td>'+ item.PointNumber + '</td>\
       <td><div style="display:none">' + item.MessageProfile + '</div>点我查看</td>\
       <td>' + tools.timeFormat(eval('new '+item.Time.replace("/", "").replace("/", "")), "yyyy-MM-dd HH:mm:ss") + '</td>\
       <td>' + tools.timeFormat(eval('new ' + item.Time_Update.replace("/", "").replace("/", "")), "yyyy-MM-dd HH:mm:ss") + '</td>\
        <td><a  href="/blogMS/Detail?type=edit&id='+item.id+'" target="_blank" class="btn btn-metis-6 btn-xs btn-grad btn-rect" data-original-title="" title="">编辑</a>\
<a  onclick="del('+"'"+item.id+"'"+')" target="_blank" class="btn btn-metis-6 btn-xs btn-grad btn-rect" data-original-title="" title="">删除</a></td>\
      </tr>';
            obj.append(ssContent);
        }



    }
    function del(id)
    {
        $.post("/blogMS/ShuoShuoDetailAction", { "id": id, "actionType": "delete" }, function (mytable, status) {
            if (status == "success") {
                alert("删除成功");
                //刷新
                Initailing();
            }
        });
    }







